import { isEmpty } from 'lodash';
import session from './session';

const KEY = 'COLORSIZE';

const { get, set } = session;

export const colorData = ['#EC4242', '#FE784B', '#F0C030', '#32AF47', '#2288FF', '#000000', '#A4A4A4', '#FFFFFF'];
// export const sizeData = [4, 8, 12];
export const newSizeData = [1, 4, 12];

const setSizeColor = (name, data) => {
  const deep = getAll();
  deep[name] = data;
  set(KEY, JSON.stringify(deep));
};

const getSizeColor = (name) => {
  const deep = getAll();
  // 如果是空的，填充默认值
  if (isEmpty(deep[name])) {
    deep[name] = {
      icon: name,
      size: newSizeData[1], // 默认为第二个大小 4
      color: colorData[0], // 默认第一个颜色
    };
  }
  return deep[name];
};

const getAll = () => {
  return JSON.parse(get(KEY) || '{}');
};

export { setSizeColor, getSizeColor, getAll };
